package gui.cen;

import gui.Segl2;
import gui.cen.south.South;
import gui.cen.read.ReadDisp;
import gui.cen.table.TableDisp;
import gui.cen.tree.TreeDisp;
import gui.utils.Borders;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import javax.swing.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Center extends JPanel{
    public static int WIDGE_WIDTH = 200;
    public static int WIDGE_SIDE = 60;
    public static int WIDGE_TOP = 30;

    private Segl2 SegL2;
    private TableDisp tbl;
    private South south;
    private TreeDisp tlw;
    private ReadDisp rd;
    private CardLayout layout;
    private JPanel p1;

    public Center(Segl2 SegL2, int which){
        this.setLayout(new BorderLayout());
        this.SegL2 = SegL2;
        this.setBackground(new Color(102, 102, 102));
        this.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        Borders.setCharHeightAndWidth();
        south = new South(this, SegL2);
        this.add(south,BorderLayout.SOUTH);
        p1 = new JPanel();
        this.add(p1,BorderLayout.CENTER);
        layout = new CardLayout();
        p1.setLayout(layout);
        p1.add(tbl = new TableDisp(this, SegL2), "Table");
        p1.setBorder(BorderFactory.createEmptyBorder(0,2,0,2));
        layout.show(p1, "Table");
        this.setVisible(true);
    }

    public void setFilterLVL_label(){
        tbl.setFilterLVL_label();
        rd.setFilterLVL_label();
        tlw.setFilterLVL_label();
    }

    public void msg(String msg){SegL2.msg(msg);}
    public void idPrg(int which){SegL2.inDetProg(which);}
    public void dPrg(int which, int val){SegL2.detProg(which, val);}
    public void refreshContainer(){SegL2.refreshContainer();}
    public void loadCard(int which){
        if(which==Segl2.TABLE){if(tbl==null){p1.add(tbl = new TableDisp(this, SegL2), "Table");}layout.show(p1, "Table");}
        else if(which==Segl2.TREE){if(tlw==null){p1.add(tlw = new TreeDisp(this, SegL2), "Tree");}layout.show(p1, "Tree");}
        else if(which==Segl2.READ){if(rd==null){p1.add(rd = new ReadDisp(this, SegL2), "Read");}layout.show(p1, "Read");}
    }
    public void updateTable(){tbl.updateTable();}
    public void updateReads(){rd.updateReads();}
    public void updateTree(){tlw.updateTree();}
    public void updatePlots(){south.updatePlots();}
    public TreeDisp getTreeDisplay(){return tlw;}
}